﻿namespace Leetcode.N0123;
public class Solution
{
    public int MaxProfit(int[] prices)
    {
        var buy1 = -prices[0];
        var buy2 = -prices[0];
        var sell1 = 0;
        var sell2 = 0;
        for (int i = 1; i < prices.Length; i++)
        {
            buy1 = Math.Max(buy1, -prices[i]);
            sell1 = Math.Max(sell1, buy1 + prices[i]);
            buy2 = Math.Max(buy2, sell1 - prices[i]);
            sell2 = Math.Max(sell2, buy2 + prices[i]);
        }
        return sell2;
    }
}
